<template>
	<view>
		<picker @change="PickerChange" :value="index" :range="picker">
				<view class="picker">
					{{index>-1?picker[index]:'请选择'}}
				</view>
		</picker>
	</view>
</template>

<script>
	import {mapState, mapActions} from 'vuex';
	export default {
		data() {
			return {
				CustomBar: this.CustomBar,
				picker: [],
				pickerValue:[],
				index:-1
			};
		},
		computed:{
			...mapState(["HOST_URL", "sessionId"])
		},
		mounted() {
			this.getDictValue();
			if(this.index == -1){
				this.index = 0;
			}
		},
		methods: {
			...mapActions(["JAjax"]),
			PickerChange(e) {
				this.index = e.detail.value
			},
			getDictValue(){
				this.JAjax({
					url: '/a/sys/dictData/listData?dictType=' + this.dict,
					success: data=>{
						if (data.statusCode == 200 && data.data) {
							this.picker = []
							for (var i = 0; i < data.data.length; i++) {
								this.picker.push(data.data[i].dictLabel)
								this.pickerValue.push(data.data[i].dictValue)
							}
						}
					}
				});
				// uni.request({
				// 	url: this.HOST_URL + '/a/sys/dictData/listData?dictType=' + this.dict + '&t=' + new Date().getTime() + '&__sid=' +
				// 		this.sessionId,
				// 	success: (data) => {
				// 		if (data.statusCode == 200 && data.data) {
				// 			this.picker = []
				// 			for (var i = 0; i < data.data.length; i++) {
				// 				this.picker.push(data.data[i].dictLabel)
				// 				this.pickerValue.push(data.data[i].dictValue)
				// 			}
				// 		}
				// 	},
				// 	fail: (data, code) => {
						
				// 	},
				// })
			}
		},
		watch:{
			index(){
				console.log("index change")
				this.$emit('input', this.pickerValue[this.index]);
			    this.$emit('change', this.pickerValue[this.index]);
			}
		},
		props: {
			dict: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
			value:{
				type: String,
				default: ''
			}
		},
	}
</script>

<style>
</style>